package cn.wen.eeayjoke.ui;

import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import android.os.IBinder;
import android.view.View;
import android.widget.Toast;

import com.wen.routerdemo.IUserAidl;
import com.wen.web.WebManager;

import cn.wen.core.titlebar.DefTitleBar;
import cn.wen.core.ui.AppActivity;
import cn.wen.eeayjoke.R;

/**
 * WebViw测试--用的是腾讯X5内核
 */
public class WebTestActivity extends AppActivity {
    IUserAidl userAidl;
    ServiceConnection conn = new ServiceConnection() {
        @Override
        public void onServiceConnected(ComponentName name, IBinder service) {
            userAidl = IUserAidl.Stub.asInterface(service);
            Toast.makeText(WebTestActivity.this, "onServiceConnected", Toast.LENGTH_SHORT).show();
        }

        @Override
        public void onServiceDisconnected(ComponentName name) {
            Toast.makeText(WebTestActivity.this, "onServiceDisconnected", Toast.LENGTH_SHORT).show();
        }
    };

    @Override
    public Object getContentLayout() {
        return R.layout.activity_web_test;
    }


    /**
     * 打开WebActivity
     */
    public void open(View view) {
        WebManager.getInstance().startWebActivity(this, "https://www.baidu.com");
    }

    public void bind(View view) {
        Intent service = new Intent();
        service.setAction("com.wen.user.service");
        service.setPackage("com.wen.routerdemo");
        bindService(service, conn, Context.BIND_AUTO_CREATE);
    }

    @Override
    protected void onDestroy() {
        unbindService(conn);
        super.onDestroy();
    }

    @Override
    protected void initTitle(DefTitleBar titleBar) {
        titleBar.setTitle("WebViw测试");
    }


    public void get(View view) {
        if (userAidl==null){
            Toast.makeText(WebTestActivity.this, "unBinder", Toast.LENGTH_SHORT).show();
        }else {
            try {
                Toast.makeText(WebTestActivity.this, userAidl.getUserName()+":"+userAidl.getPwd(), Toast.LENGTH_SHORT).show();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
}
